/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package xcore.constraint.provider;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;

import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;

import xcore.constraint.util.ConstraintAdapterFactory;

/**
 * This is the factory that is used to provide the interfaces needed to support Viewers.
 * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
 * The adapters also support Eclipse property sheets.
 * Note that most of the adapters are shared among multiple instances.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public class ConstraintItemProviderAdapterFactory extends ConstraintAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
	/**
	 * This keeps track of the root adapter factory that delegates to this adapter factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposedAdapterFactory parentAdapterFactory;

	/**
	 * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IChangeNotifier changeNotifier = new ChangeNotifier();

	/**
	 * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Collection<Object> supportedTypes = new ArrayList<Object>();

	/**
	 * This constructs an instance.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConstraintItemProviderAdapterFactory() {
		supportedTypes.add(IEditingDomainItemProvider.class);
		supportedTypes.add(IStructuredItemContentProvider.class);
		supportedTypes.add(ITreeItemContentProvider.class);
		supportedTypes.add(IItemLabelProvider.class);
		supportedTypes.add(IItemPropertySource.class);
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XIntVar} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XIntVarItemProvider xIntVarItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XIntVar}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXIntVarAdapter() {
		if (xIntVarItemProvider == null) {
			xIntVarItemProvider = new XIntVarItemProvider(this);
		}

		return xIntVarItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XSum} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XSumItemProvider xSumItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XSum}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXSumAdapter() {
		if (xSumItemProvider == null) {
			xSumItemProvider = new XSumItemProvider(this);
		}

		return xSumItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XNeg} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XNegItemProvider xNegItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XNeg}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXNegAdapter() {
		if (xNegItemProvider == null) {
			xNegItemProvider = new XNegItemProvider(this);
		}

		return xNegItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XScalar} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XScalarItemProvider xScalarItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XScalar}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXScalarAdapter() {
		if (xScalarItemProvider == null) {
			xScalarItemProvider = new XScalarItemProvider(this);
		}

		return xScalarItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XEQ} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XEQItemProvider xeqItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XEQ}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXEQAdapter() {
		if (xeqItemProvider == null) {
			xeqItemProvider = new XEQItemProvider(this);
		}

		return xeqItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XNEQ} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XNEQItemProvider xneqItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XNEQ}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXNEQAdapter() {
		if (xneqItemProvider == null) {
			xneqItemProvider = new XNEQItemProvider(this);
		}

		return xneqItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XLEQ} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XLEQItemProvider xleqItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XLEQ}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXLEQAdapter() {
		if (xleqItemProvider == null) {
			xleqItemProvider = new XLEQItemProvider(this);
		}

		return xleqItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XLT} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XLTItemProvider xltItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XLT}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXLTAdapter() {
		if (xltItemProvider == null) {
			xltItemProvider = new XLTItemProvider(this);
		}

		return xltItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XIntCst} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XIntCstItemProvider xIntCstItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XIntCst}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXIntCstAdapter() {
		if (xIntCstItemProvider == null) {
			xIntCstItemProvider = new XIntCstItemProvider(this);
		}

		return xIntCstItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XIntVarRef} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XIntVarRefItemProvider xIntVarRefItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XIntVarRef}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXIntVarRefAdapter() {
		if (xIntVarRefItemProvider == null) {
			xIntVarRefItemProvider = new XIntVarRefItemProvider(this);
		}

		return xIntVarRefItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XAdd} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XAddItemProvider xAddItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XAdd}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXAddAdapter() {
		if (xAddItemProvider == null) {
			xAddItemProvider = new XAddItemProvider(this);
		}

		return xAddItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XSub} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XSubItemProvider xSubItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XSub}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXSubAdapter() {
		if (xSubItemProvider == null) {
			xSubItemProvider = new XSubItemProvider(this);
		}

		return xSubItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XMult} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XMultItemProvider xMultItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XMult}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXMultAdapter() {
		if (xMultItemProvider == null) {
			xMultItemProvider = new XMultItemProvider(this);
		}

		return xMultItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XDiv} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XDivItemProvider xDivItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XDiv}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXDivAdapter() {
		if (xDivItemProvider == null) {
			xDivItemProvider = new XDivItemProvider(this);
		}

		return xDivItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XPpcm} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XPpcmItemProvider xPpcmItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XPpcm}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXPpcmAdapter() {
		if (xPpcmItemProvider == null) {
			xPpcmItemProvider = new XPpcmItemProvider(this);
		}

		return xPpcmItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link xcore.constraint.XIntCstRef} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XIntCstRefItemProvider xIntCstRefItemProvider;

	/**
	 * This creates an adapter for a {@link xcore.constraint.XIntCstRef}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXIntCstRefAdapter() {
		if (xIntCstRefItemProvider == null) {
			xIntCstRefItemProvider = new XIntCstRefItemProvider(this);
		}

		return xIntCstRefItemProvider;
	}

	/**
	 * This returns the root adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComposeableAdapterFactory getRootAdapterFactory() {
		return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
	}

	/**
	 * This sets the composed adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) {
		this.parentAdapterFactory = parentAdapterFactory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isFactoryForType(Object type) {
		return supportedTypes.contains(type) || super.isFactoryForType(type);
	}

	/**
	 * This implementation substitutes the factory itself as the key for the adapter.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter adapt(Notifier notifier, Object type) {
		return super.adapt(notifier, this);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object adapt(Object object, Object type) {
		if (isFactoryForType(type)) {
			Object adapter = super.adapt(object, type);
			if (!(type instanceof Class) || (((Class<?>)type).isInstance(adapter))) {
				return adapter;
			}
		}

		return null;
	}

	/**
	 * This adds a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void addListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.addListener(notifyChangedListener);
	}

	/**
	 * This removes a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void removeListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.removeListener(notifyChangedListener);
	}

	/**
	 * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void fireNotifyChanged(Notification notification) {
		changeNotifier.fireNotifyChanged(notification);

		if (parentAdapterFactory != null) {
			parentAdapterFactory.fireNotifyChanged(notification);
		}
	}

	/**
	 * This disposes all of the item providers created by this factory. 
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void dispose() {
		if (xIntVarItemProvider != null) xIntVarItemProvider.dispose();
		if (xSumItemProvider != null) xSumItemProvider.dispose();
		if (xNegItemProvider != null) xNegItemProvider.dispose();
		if (xScalarItemProvider != null) xScalarItemProvider.dispose();
		if (xeqItemProvider != null) xeqItemProvider.dispose();
		if (xneqItemProvider != null) xneqItemProvider.dispose();
		if (xleqItemProvider != null) xleqItemProvider.dispose();
		if (xltItemProvider != null) xltItemProvider.dispose();
		if (xIntCstItemProvider != null) xIntCstItemProvider.dispose();
		if (xIntVarRefItemProvider != null) xIntVarRefItemProvider.dispose();
		if (xAddItemProvider != null) xAddItemProvider.dispose();
		if (xSubItemProvider != null) xSubItemProvider.dispose();
		if (xMultItemProvider != null) xMultItemProvider.dispose();
		if (xDivItemProvider != null) xDivItemProvider.dispose();
		if (xPpcmItemProvider != null) xPpcmItemProvider.dispose();
		if (xIntCstRefItemProvider != null) xIntCstRefItemProvider.dispose();
	}

}
